package Sort;

import java.util.Arrays;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2024/8/26-上午11:15
 * Since  :   1.0
 * Version:   1.0
 */
public class QuickSort {

    public static void quick(int[] arr, int left, int right) {
        if (left >= right) {
          return ;
        }

        int l = left;
        int r = right;
        int pivot = arr[l];
        while (l != r) {
            while (arr[r] >= pivot && l < r) {
                r--;
            }
            while (arr[l] <= pivot && l < r) {
                l++;
            }
            int temp = arr[r];
            arr[r] = arr[l];
            arr[l] = temp;

        }

        arr[left] = arr[r];
        arr[r] = pivot;
        quick(arr, left, r - 1);
        quick(arr, r + 1, right);


    }

    public static void main(String[] args) {
        int[] input = {3, 6, 8, 10, 1, 2, 1};
      QuickSort.quick(input,0,input.length-1);
        System.out.println(Arrays.toString(input));

    }

}
